import pygame
from pygame.locals import *

from code import InteractiveInterpreter

class CommandModel(InteractiveInterpreter):
    def __init__(self):
        InteractiveInterpreter.__init__(self)
        self.currentSource = ''
    def __getitem__(self,key):
        return self.locals[key]
    """
    def runcode(self,code):
        return InteractiveInterpreter.runcode(self,code)
    """
    def runsource(self,source):
        if not self.currentSource:
            returnValue = InteractiveInterpreter.runsource(self,source)
        else:
            returnValue = InteractiveInterpreter.runsource(
                self,
                self.currentSource)
        if returnValue:
            self.currentSource += source
        else:
            self.currentSource = ''
        return returnValue
    """
    def showsyntaxerror(self,filename=None):
        return InteractiveInterpreter.showsyntaxerror(self,filename)
    def showtraceback(self):
        return InteractiveInterpreter.showtraceback(self)
    def write(self,data):
        return InteractiveInterpreter.write(self,data)
    """

class CLICommandModel(CommandModel):
    def write(self,data):
        print '!! Caught data:',data

class GameCommandModel(CommandModel):
    def __init__(self,masterControl=None):
        CommandModel.__init__(self)
        self.masterControl = masterControl
    def write(self,data):
        self.masterControl.handleData(data)
    

class CommandController:
    def __init__(self,model,view):
        self.model = model
        self.view = view
    def processEvent(self,event):
        self.view.setCurrent


class CommandView(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.font = pygame.font.Font(None, 20)
        self.font.set_italic(1)
        self.color = Color('white')
        self.lastscore = -1
        self.update()
        self.rect = self.image.get_rect().move(10, 450)
    def update(self):
        if SCORE != self.lastscore:
            self.lastscore = SCORE
            msg = "Score: %d" % SCORE
            self.image = self.font.render(msg, 0, self.color)

if __name__=='__main__':
    pass
